<?php

function isValid($s) {
    if(empty($s)){
        return true;
    }
    $stack = new SplStack();
    $sArr = str_split($s);
    if(count($sArr)%2 > 0){
        return false;
    }
    foreach ($sArr as $item){
        if(in_array($item,array("(","[","{"))){
            $stack->push($item);
        }else{
            if($stack->count() < 1){
                return false;
            }
            $popStr = $stack->pop();
            if($popStr == "(" && $item != ")"){
                return false;
            }
            if($popStr == "[" && $item != "]"){
                return false;
            }
            if($popStr == "{" && $item != "}"){
                return false;
            }
        }
    }
    if($stack->count() > 0){
        return false;
    }
    return true;
}

var_dump(isValid("{{"));